<?php

/**
 * This is the model class for table "{{review}}".
 *
 * The followings are the available columns in table '{{review}}':
 * @property integer $id
 * @property string $title
 * @property string $content
 * @property string $description
 * @property string $cons
 * @property string $pros
 * @property integer $overallrate
 * @property integer $usability
 * @property integer $stability
 * @property integer $installation
 * @property integer $functionally
 * @property integer $appearance
 * @property integer $program_id
 * @property integer $user_id
 *
 * The followings are the available model relations:
 * @property Comment[] $comments
 * @property Program $program
 * @property Users $user
 */
class Review extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Review the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{review}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('title, content, description, cons, pros, overallrate, usability, stability, installation, functionally, appearance, program_id, user_id', 'required'),
			array('overallrate, usability, stability, installation, functionally, appearance, program_id, user_id', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, title, content, description, cons, pros, overallrate, usability, stability, installation, functionally, appearance, program_id, user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'comments' => array(self::HAS_MANY, 'Comment', 'review_id'),
			'program' => array(self::BELONGS_TO, 'Program', 'program_id'),
			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'title' => 'Title',
			'content' => 'Content',
			'description' => 'Description',
			'cons' => 'Cons',
			'pros' => 'Pros',
			'overallrate' => 'Overallrate',
			'usability' => 'Usability',
			'stability' => 'Stability',
			'installation' => 'Installation',
			'functionally' => 'Functionally',
			'appearance' => 'Appearance',
			'program_id' => 'Program',
			'user_id' => 'User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('cons',$this->cons,true);
		$criteria->compare('pros',$this->pros,true);
		$criteria->compare('overallrate',$this->overallrate);
		$criteria->compare('usability',$this->usability);
		$criteria->compare('stability',$this->stability);
		$criteria->compare('installation',$this->installation);
		$criteria->compare('functionally',$this->functionally);
		$criteria->compare('appearance',$this->appearance);
		$criteria->compare('program_id',$this->program_id);
		$criteria->compare('user_id',$this->user_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}